$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'../..','ext_pr1/lib')
require 'ext_pr1_v4'

# hash invert_exact

class Hash
   def invert_exact
      ret = Hash[]
      self.each {|key,value| ret.include?(value) ? check_pre(false) : ret[value]=key}
      ret
   end
end

#Set symm_diff
class Set
def diff_symm(val)
check_pre((val.set?))
new=[]
self.each { |elem| val.include?(elem) ? new.delete(elem) : new << elem  }
val.each { |elem| self.include?(elem) ? new.delete(elem) : new << elem  }
new
end
end
#p(Set[1,2,"a"].diff_symm(Set[1,3,"b"]))

#size_endrec

class List
   def size_endrec
      self.empty? ? 0 : size_endrec_(0,self)
   end
   def size_endrec_(akku,list)
      list.empty? ? akku : size_endrec_(akku+=1, list.rest)
   end
end

 #hash without_keys(enum)
 class Hash
 def without_keys(val)
  check_pre((val.is_a?(Enumerable)))
  new={}
   self.each { |key,value|  val.include?(key) ? new.delete(val)  : new[key]=value}
  new
 end
 end
# puts({"a" => 100,"b" => 200,"c" => 300}.without_keys(["a"]))
 
#add_int_comps

def add_int_comps()
 puts("too hard")
end

#raise_to(n)
class Integer
#def raise_to(n)
#  n>=0 ? n.even? ? raise_to_even(n,self) : raise_to_odd(n,self) : check_pre((false))
#end
#
#def raise_to_odd(akku,basis)
#  akku == 1 ? basis : raise_to_even(akku-1,(basis*basis))
#end
#
#def raise_to_even(akku,basis)
#  akku == 1 ? basis : raise_to_odd(akku/2,(basis*basis))
#end

#  def raise_to(n)
#    check_pre((n>=0))
#     help_raise_to(n,self)
#  end
#
#  def help_raise_to(akku,basis)
#    akku >= 0 ? (akku == 1 ? basis : help_raise_to(akku-1,(basis*basis))) : (akku == 1 ? basis : help_raise_to(akku/2,(basis*basis)))
#  end
#
#puts(2.raise_to(-2))

def raise_to(n)
  check_pre((n.int? and n >= 0))
  if n == 1 then self
  elsif n%2 == 0 then (self.raise_to(n/2))**2
  elsif n%2 == 1 then self*self.raise_to(n-1)
  end
end
end
#puts(-2.raise_to(2))

#tree depth
class Array
def tree_depth()
  count=0
  self.each { |item| item.array? ? (count += item.tree_depth) : count =+ 1}
count  
end
end

puts([[1,2],3,[1,[2,[3,4]]]].tree_depth)